﻿import { freeForm } from '/plugins/lgform/lg.form.2.1.js';
var form = {
    model: function () {       
    },
    component: {
        name: "lg-form",
        data: {
            props: {
                data: {
                    type: Object
                },
                skin: {
                    type: String
                },
                btText: {
                    type: String,
                    default: "立即提交"
                },
                //0默认填写 1只读
                renderType: {
                    type: Number,
                    default: 0
                },
                requestParam: {
                    type: Object,
                    default: null
                }
            },
            data() {
                return {
                    items: []
                }
            },
            mounted: function () {
                var items = this.data;
                for (let i in items) {
                    items[i].Data.error = false;
                    items[i].Data.errMsg = ""
                }
                this.items = items;
            },
            template: `
            <div class="lg-form-body">
              <div class="Component">
                <template v-for="item in data">
                  <component
                    :is="GetComponent(item.TypeName)"
                    :items="data"
                    :data="item.Data"
                    :request-param="requestParam"
                    v-model:value="item.Data.Value"
                    v-show="item.Data.IsRender!=false"
                    v-on:done="done"
                    v-on:event="onEvent"
                    :renderType="renderType">
                  </component>                             
                </template>
              </div>
              <div style="padding:15px;text-align:center" v-if="renderType==0">
                <button class="lg-btn lg-btn-lg" v-on:click="submit()">{{btText||'立即提交'}}</button>
              </div>
            </div>
            `,
            methods: {
                GetComponent: function (key) {
                    return freeForm.getComponent(key).component.name;                   
                },
                submit: function () {                  
                    this.$emit("submit");
                },
                done: function (data) {
                    this.$emit("done", data);
                },
                onEvent: function (data) {
                    this.$emit("event", data);
                }
            }

        }
    }
}

export { form }